********************************************************************
* this code is based on the original Science paper's replication code 
* the major extension is to include battleground states indicators 
********************************************************************

clear
set more off
set segmentsize 1g

use "./data/processed/thanksgiving2016_processed.dta",clear 

********************************************************************
* Table 4 : effects of political mismatch on the duration of Thanskgiving dinner by close election status
********************************************************************
estimates clear 
reghdfe Time_At_Thanksgiving c.P_Diff bg_tg std_Pol_Ads /*
*/ block_white block_black block_hispanic block_asian bg_male bg_unemployed bg_avgcommutetime  /*
*/ tract_foreignbor tract_medianage tract_urbanarea tract_rural tract_medhhinc /*
*/  if st_same & H_TR_H, noabsorb vce(cluster PrecXPrec)
	estadd local block_control "Yes"
	estadd local geo_control "No"
estimates store m1

reghdfe Time_At_Thanksgiving c.P_Diff std_Pol_Ads /*
*/ block_white block_black block_hispanic block_asian bg_male bg_unemployed bg_avgcommutetime  /*
*/ tract_foreignbor tract_medianage tract_urbanarea tract_rural tract_medhhinc /*
*/  if st_same & H_TR_H & bg_tg == 0, noabsorb vce(cluster PrecXPrec)
	estadd local block_control "Yes"
	estadd local geo_control "No"
estimates store m2

reghdfe Time_At_Thanksgiving c.P_Diff std_Pol_Ads /*
*/ block_white block_black block_hispanic block_asian bg_male bg_unemployed bg_avgcommutetime  /*
*/ tract_foreignbor tract_medianage tract_urbanarea tract_rural tract_medhhinc /*
*/  if st_same & H_TR_H & bg_tg == 1, noabsorb vce(cluster PrecXPrec)
	estadd local block_control "Yes"
	estadd local geo_control "No"
estimates store m3

reghdfe Time_At_Thanksgiving c.P_Diff##c.bg_tg  std_Pol_Ads /*
*/ block_white block_black block_hispanic block_asian bg_male bg_unemployed bg_avgcommutetime  /*
*/ tract_foreignbor tract_medianage tract_urbanarea tract_rural tract_medhhinc /*
*/  if st_same & H_TR_H, noabsorb  vce(cluster PrecXPrec)
	estadd local block_control "Yes"
	estadd local geo_control "No"
estimates store m4

reghdfe Time_At_Thanksgiving c.P_Diff##c.bg_tg  /*
*/ block_white block_black block_hispanic block_asian bg_male bg_unemployed bg_avgcommutetime  /*
*/ tract_foreignbor tract_medianage tract_urbanarea tract_rural tract_medhhinc /*
*/  if st_same & H_TR_H, absorb(County_Pairs)  vce(cluster PrecXPrec)
	estadd local block_control "Yes"
	estadd local geo_control "CountyPair"
estimates store m5

esttab m1 m2 m3 m4 m5  using "./output/table_main_thanksgiving_2016.rtf", replace rtf    ///
	b(%9.2f) se(%9.2f) star(+ 0.10 * 0.05 ** 0.01) keep(P_Diff std_Pol_Ads bg_tg c.P_Diff#c.bg_tg ) ///
		mgroups("All" "nonclose" "close" "All", pattern(1 1 1 1 0))  ///
		label legend stats (N block_control geo_control , fmt(%9.0gc %9.0gc %9.0gc)  ///
		label("N" "Block/track-level controls" "dyadic FE"))  ///
		varlabels(_cons "Constant")  nonotes 	 ///
		mtitles("model1" "model2" "model3" "model4" "model5")

********************************************************************
* Table 5 : thihs time, modeling staying home decision
********************************************************************
tab Thanksgiving_Home if Was_Home_Early == 1
tab Was_Home_Early 

estimates clear 
reghdfe Thanksgiving_Home bg_home  /*
*/ if Was_Home_Early, noabsorb  vce(cluster prec_code)
	estadd local block_control "No"
estimates store m0

reghdfe Thanksgiving_Home bg_home  /*
*/ block_white block_black block_hispanic block_asian bg_male bg_unemployed bg_avgcommutetime  /*
*/ tract_foreignbor tract_medianage tract_urbanarea tract_rural tract_medhhinc /*
*/ if Was_Home_Early, noabsorb  vce(cluster prec_code)
	estadd local block_control "Yes"
estimates store m1

reghdfe Thanksgiving_Home bg_home std_Pol_Ads /*
*/ block_white block_black block_hispanic block_asian bg_male bg_unemployed bg_avgcommutetime  /*
*/ tract_foreignbor tract_medianage tract_urbanarea tract_rural tract_medhhinc /*
*/ if Was_Home_Early, noabsorb  vce(cluster prec_code)
	estadd local block_control "Yes"
estimates store m2

reghdfe Thanksgiving_Home c.bg_home##c.std_Pol_Ads /*
*/ block_white block_black block_hispanic block_asian bg_male bg_unemployed bg_avgcommutetime  /*
*/ tract_foreignbor tract_medianage tract_urbanarea tract_rural tract_medhhinc /*
*/ if Was_Home_Early, noabsorb  vce(cluster prec_code)
	estadd local block_control "Yes"
estimates store m3

esttab m0 m1 m2 m3 using "./output/table_add_thanksgiving_2016_stay_home.rtf", replace rtf     ///
	b(%9.3f) se(%9.3f) star(+ 0.10 * 0.05 ** 0.01) keep(bg_home std_Pol_Ads c.bg_home#c.std_Pol_Ads ) ///
		mgroups("Staying home", pattern(1 0 0 0 ))  ///
		label legend stats (N block_control , fmt(%9.0gc %9.0gc) ///
		label("N" "Block/track controls")) ///
		varlabels(_cons "Constant")  nonotes 	 ///
		mtitles("model1" "model2" "model3" "model4")

* export data to R for plotting 
keep if H_TR_H & st_same
keep bg_tg P_Diff Time_At_Thanksgiving prec_code travel_prec_code PrecXPrec
save "./data/processed/thanksgiving2016_plot.dta",replace 


